let page = {
    p:1,
    num:5,
    list:[]
}
$().ready(function(){
    function init(){
        getNewsList(page.p,page.num);
        getTj();
    }
    init();
    $('#more').on('click',function(){
        page.p = page.p + 1;
        getNewsList(page.p,page.num);
    })
})
//获取新闻列表
function getNewsList(p,num){
    getAjax('/Api/New/get_jtxw',function(res){
        let list = page.list;
        console.log(list,page.p);
        if(res.ok == 0){
            $('#more').css('display','none');
        }
        if(p != 1){
            // console.log(res.list);
            for(let j in res.list){
                list.push(res.list[j]);
            }
            page.list = list;
        }else{
            page.list = res.list;
        }
        let headlineH = '<a href="news-details.html?id='+page.list[0].id+'">';
        headlineH += '<div class="head-line-img" style="background: url('+page.list[0].title_img+') no-repeat center center /cover"></div>';
        headlineH += '<div class="head-line-header">';
        headlineH += '<div class="date">'+page.list[0].date+'</div>';
        headlineH += '<div class="title news-main-width">'+page.list[0].title+'</div>';
        headlineH += '</div><p class="sub-content theme-color02">'+page.list[0].sub_content+'</p>';
        headlineH += '<div class="check-head-line">头条详情 <img src="img/news/check-head-line-icon.png" ></div> </a>';
        $('#head-line').html(headlineH);
        let ulHtm = '';
        for(let h=1;h<page.list.length;h++){
            ulHtm += '<li><a href="news-details.html?id='+page.list[h].id+'">';
            ulHtm += '<div class="date">'+page.list[h].date+'</div>';
            ulHtm += '<div class="news-info news-main-width">';
            ulHtm += '<p class="title">'+page.list[h].title+'</p>';
            ulHtm += '<p class="sub-content theme-color02">'+page.list[h].sub_content+'</p>';
            ulHtm +=  '</div>';
            ulHtm +=  '</a>';
            ulHtm +=  '</li>';
        }
        $('#news-list').html(ulHtm);
    },{
        p:p,
        num:num
    })
}
//获取推介
function getTj(){
    getAjax('/Api/New/get_tj',function(res){
        console.log(res);
        let html = ' <a href="news-details.html?id='+res.id+'">';
        html += '<div class="recommend-news-img"><img src="'+res.title_img+'" alt=""></div>'
        html += '<p class="recommend-news-title">'+res.title+'</p>';
        html += '<p class="recommend-news-sub-content theme-color02">'+res.sub_content+'</p>';
        $('#tj').html(html);
    })
}
